<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="include :: header('处理反馈')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content ibox-content">
        <form class="form-horizontal m" id="form-contact-edit" th:object="${cmsContact}">
            <input name="contactId" th:field="*{contactId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <select name="contactType" class="form-control disabled" disabled th:with="type=${@dictTag.getType('cms_contact_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{contactType}"></option>>
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">主题：</label>
                <div class="col-sm-8">
                    <input name="subject" disabled th:field="*{subject}" class="form-control disabled" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">
                    <div id="contentBox" th:utext="${cmsContact.content}"> </div>     
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">邮件：</label>
                <div class="col-sm-8">
                    <input name="email" th:field="*{email}" readonly class="form-control disabled" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">联系方式：</label>
                <div class="col-sm-8">
                    <input name="touch" th:field="*{touch}" readonly class="form-control disabled" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">结果：</label>
                <div class="col-sm-8">
                    <div id="handResultBox" th:utext="${cmsContact.handleResult}"> </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dictTag.getType('cms_contact_visible')}">
                        <input type="radio" th:id="${dict.dictCode}" name="visible" th:value="${dict.dictValue}"
                            th:checked="${dict.default}" th:field="*{visible}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn  btn-primary valid" onclick="submitHandler()"><i class="fa fa-check"></i>处理</button>&nbsp;
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">
        var prefix = ctx + "cms/contact";
        $("#form-contact-edit").validate({
            focusCleanup: true
        });
        function submitHandler() {
            var data = $('#form-contact-edit').serializeArray();
            data.push({ "name": "content", "value":$("#contentBox").summernote('code')});
            data.push({ "name": "handleResult", "value":$("#handResultBox").summernote('code')});
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/edit", data);
            }
        }
        $("#contentBox").summernote({
            lang: 'zh-CN', // default: 'en-US'  
            focus: true,
            disable: true,
            callbacks: {
                onImageUpload: function (files) {
                    // upload image to server and create imgNode...
                    sendFile(files[0],"#contentBox");
                }
            }
        });

        $("#handResultBox").summernote({
            lang: 'zh-CN', // default: 'en-US'  
            focus: true,
            disable: true,
            callbacks: {
                onImageUpload: function (files) {
                    // upload image to server and create imgNode...
                    sendFile(files[0],"#handResultBox");
                }
            }
        });

         //编辑器
         function sendFile(files,handResultBox) {
            var data = new FormData();
            data.append("file", files);
            $.ajax({
                data: data,
                type: "POST",
                url: ctx + "oly/oss/upload",
                cache: false,
                contentType: false,
                processData: false,
                success: function (res) {
                    //data为图片请求地址
                    let url = res.data.domain + res.data.fk;
                    $(handResultBox).summernote('insertImage', url, res.data.fileName);
                },
                error: function () {
                    layer.alert('上传失败!');
                    return;
                }

            });
        }
        $("#contentBox").summernote('disable')
    </script>
</body>

</html>